#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time    : 2025/3/27 23:21
@Author  : HZP
@File    : router.py
"""
from dataclasses import dataclass

from flask import Flask, Blueprint
from injector import inject

from internal.handler import AppHandler, AuthHandler


@inject
@dataclass
class Router:
    app_handler: AppHandler
    auth_handler: AuthHandler

    def register_router(self, app: Flask):
        bp = Blueprint("llmops", __name__, url_prefix="")
        openapi_bp = Blueprint("openapi", __name__, url_prefix="")

        """应用相关接口"""
        bp.add_url_rule("/ping", view_func=self.app_handler.ping)
        # bp.add_url_rule("/apps", view_func=self.app_handler.get_apps_with_page)
        bp.add_url_rule("/apps", methods=["POST"], view_func=self.app_handler.create_app)
        bp.add_url_rule("/apps/<uuid:app_id>", view_func=self.app_handler.get_app)
        bp.add_url_rule("/apps/<uuid:app_id>", methods=["POST"],
                        view_func=self.app_handler.update_app)
        bp.add_url_rule("/apps/<uuid:app_id>/delete", methods=["POST"],
                        view_func=self.app_handler.delete_app)
        # bp.add_url_rule("/apps/<uuid:app_id>/copy", methods=["POST"],
        #                 view_func=self.app_handler.copy_app)
        # bp.add_url_rule("/apps/<uuid:app_id>/draft-app-config",
        #                 view_func=self.app_handler.get_draft_app_config)
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/draft-app-config",
        #     methods=["POST"],
        #     view_func=self.app_handler.update_draft_app_config,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/publish",
        #     methods=["POST"],
        #     view_func=self.app_handler.publish,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/cancel-publish",
        #     methods=["POST"],
        #     view_func=self.app_handler.cancel_publish,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/publish-histories",
        #     view_func=self.app_handler.get_publish_histories_with_page,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/fallback-history",
        #     methods=["POST"],
        #     view_func=self.app_handler.fallback_history_to_draft,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/summary",
        #     view_func=self.app_handler.get_debug_conversation_summary,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/summary",
        #     methods=["POST"],
        #     view_func=self.app_handler.update_debug_conversation_summary,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/conversations/delete-debug-conversation",
        #     methods=["POST"],
        #     view_func=self.app_handler.delete_debug_conversation,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/conversations",
        #     methods=["POST"],
        #     view_func=self.app_handler.debug_chat,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/conversations/tasks/<uuid:task_id>/stop",
        #     methods=["POST"],
        #     view_func=self.app_handler.stop_debug_chat,
        # )
        # bp.add_url_rule(
        #     "/apps/<uuid:app_id>/conversations/messages",
        #     view_func=self.app_handler.get_debug_conversation_messages_with_page,
        # )

        """登录"""
        bp.add_url_rule(
            "/auth/password-login",
            methods=["POST"],
            view_func=self.auth_handler.password_login,
        )
        bp.add_url_rule(
            "/auth/logout",
            methods=["POST"],
            view_func=self.auth_handler.logout,
        )
        app.register_blueprint(bp)
